const express = require('express')
const router =  express.Router()
const db = require('../db/index')

router.get('/getDate',(req,res)=>{
  if(!req.query.page || !req.query.limit) return send('失败')
  const sqlcounts = 'SELECT * FROM daohang'
  const a =  req.query.page * req.query.limit
  const b = a - req.query.limit
  const sql = 'select * from daohang where id >? and id<= ? '
  db.query(sql,[b,a],(err,result)=>{
    if(err) return res.send(err)
    const n = [...result]
    db.query(sqlcounts,(err,result)=>{
      if(err) return res.send('err')
      res.send({
        code:200,
        counts: result.length,
        message:'查询成功了',
        date: n
      })
    })
  })
})

module.exports = router